﻿using SketchUpAPI.NET.Enums;
using SketchUpAPI.NET.SketchUp.Exception;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SketchUpAPI.NET.Objects
{
    public class DrawingElement : Entity
    {
        #region API 函数
        /// <summary>
        /// 获取物件的边界
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="boundingBox"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementGetBoundingBox(IntPtr elem, ref BoundingBox3D boundingBox);

        /// <summary>
        /// 设置物体材质
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="material"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementSetMaterial(IntPtr elem, IntPtr material);

        /// <summary>
        /// 获取物体材质
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="material"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementGetMaterial(IntPtr elem, out IntPtr material);

        /// <summary>
        /// 获取图层
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementGetLayer(IntPtr elem, out IntPtr layer);

        /// <summary>
        /// 设置物体图层
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementSetLayer(IntPtr elem, IntPtr layer);

        /// <summary>
        /// 获取物体隐藏状态
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="hidden"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementGetHidden(IntPtr elem, out bool hidden);

        /// <summary>
        /// 设置物体隐藏状态
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="hidden"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDrawingElementSetHidden(IntPtr elem, bool hidden);
        #endregion

        /// <summary>
        /// 边界
        /// </summary>
        public BoundingBox3D BoundingBox
        {
            get
            {
                BoundingBox3D boundingBox = default;
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementGetBoundingBox(Id, ref boundingBox));
                return boundingBox;
            }
        }

        /// <summary>
        /// 物体材质
        /// </summary>
        public Material Material
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementGetMaterial(Id, out IntPtr mId));
                return new Material(mId);
            }
            set
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementSetMaterial(Id, value.Id));
            }
        }

        /// <summary>
        /// 图层
        /// </summary>
        public Layer Layer
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementGetLayer(Id, out IntPtr mId));
                return new Layer(mId);
            }
            set
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementSetLayer(Id, value.Id));
            }
        }

        /// <summary>
        /// 是否隐藏
        /// </summary>
        public bool IsHidden
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementGetHidden(Id, out bool hi));
                return hi;
            }
            set
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDrawingElementSetHidden(Id, value));
            }
        }

        internal DrawingElement(IntPtr id) : base(id)
        {

        }

        internal DrawingElement() { }
    }
}